<template>
  <!-- 1.首页 轮播 -->
  <div id="carousel" v-if="carousels.length > 0 && tops.length > 0">
    <div class="carousel-left">
      <el-carousel :interval="5000" height="360px">
        <el-carousel-item v-for="item in carousels" :key="item.id" @click.native="showDetail(item.id)">
          <img class="carousel-cover" :src="item.cover">
          <h3 class="carousel-title">
            <el-link :underline="false" class="carousel-title-top-1" @click.native="showDetail(item.id)">
              {{ item.title }}
            </el-link>
          </h3>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="carousel-right" v-if="tops.length > 0">
      <div v-for="item in tops" :key="item.id" style="height:177.5px;margin-bottom: 5px;">
        <el-image style="width: 100%; height: 100%;" :src="item.cover" fit="cover" @click.native="showDetail(item.id)">
        </el-image>

        <el-link :underline="false" class="carousel-title-top-2" @click="showDetail(item.id)">
          {{ item.title }}
        </el-link>
      </div>
    </div>
    <div class="carousel-right" v-else>
      <div>
        <el-empty description="描述文字"></el-empty>
      </div>
      <div>
        <el-empty description="描述文字"></el-empty>
      </div>
    </div>
  </div>
</template>

<script>
import {
    articleQueryList
} from '@/api/article'

export default {
    name: 'my-menu',
    data () {
        return {
            carousels: [],
            tops: []
        }
    },
    methods: {
        showDetail (articleId) {
            this.$router.push({
                path: 'articleDetail',
                query: {
                    'articleId': articleId
                }
            })
        }
    },
    mounted () {
        articleQueryList({
            isCarousel: true,
            limit: 6
        }).then((response) => {
            if (response && response.code === 200) {
                this.carousels = response.data
            }
        })

        articleQueryList({
            isTop: true,
            limit: 2
        }).then((response) => {
            if (response && response.code === 200) {
                this.tops = response.data
            }
        })
    }
}
</script>

<style scoped>
#carousel {
  width: 100%;
  height: 360px;
  padding: 0px;
  margin: 0px;
  display: flex;
  flex-direction: row;
}

.carousel-left {
  width: 68%;
}

.carousel-cover {
  width: 100%;
  height: 100%;
  /* border-radius: 4px; */
}

.carousel-title {
  position: relative;
  bottom: 60px;
  left: 10px;
  color: #fff;
  cursor: pointer;
}

.carousel-right {
  width: calc(32% - 5px);
  height: 360px;
  margin: 0px 0px 0px 5px;
  padding: 0px;
  background-color: #fff;
}

.carousel-title-top-1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0px 5px 0px 5px;
  position: relative;
  bottom: 0px;
  left: 5px;
  color: #fff;
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  cursor: pointer;
}

.carousel-title-top-2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0px 5px 0px 5px;
  position: relative;
  bottom: 40px;
  left: 5px;
  color: #fff;
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  cursor: pointer;
}
</style>
